package com.practice.config.utils;
import lombok.Data;

/**
 * Created by IntelliJ IDEA2021.3
 * @Author: Tenghw
 * @Date: 2022/12/11  21:02
 * @Description:
 */
@Data
public class PageHelper {
    private int currPage;
    private int pageSize;
    private int totalPage;
    private int totalRecord;
    private int beginIndex;

    public void init(){
        if (currPage == 0){
            currPage=1;
        }
        if (pageSize == 0){
            pageSize =10;
        }
        beginIndex = (currPage -1) * pageSize;
    }

    public void calculate(int count){
        this.totalRecord = count;
        if (count ==0){
            totalPage =0;
        }
        totalPage = count /pageSize + (count % pageSize ==0 ?0 :1);
    }

    @Override
    public String toString() {
        return "PageHelper{" +
                "currPage=" + currPage +
                ", pageSize=" + pageSize +
                ", totalPage=" + totalPage +
                ", totalRecord=" + totalRecord +
                ", beginIndex=" + beginIndex +
                '}';
    }
}
